SAP Jobsuche bei DV-Treff


Suchen
Dzaecko
  • Dzaecko
  • SAP Forum - Neuling Thema Starter
vor 13 Jahre
Guten Morgen,

da ich mich zur Zeit im Studium (leider 😉 ) mit SAP beschäftigen muss, stelle ich mein Problem hier vor.
Da ich ein Neuling bin verzeiht mir bitte wenn ich etwas schwer zu verstehen bin.

Also zu meinem Problem:

Aufgabe ist es eine Excel Tabelle in SAP zu übernehmen. Das klappt auch so weit das ich die Daten in eine interne Tabelle schreibe. Jetzt nur kurz zur Verständnis: Interne Tabellen sind so weit ich weiß ja nur im Arbeitsspeicher vorhanden... oder?
Gut hab eine identische Tabelle mit Feldern innerhalb SAP erstellt. Wie kann ich denn jetzt die Daten in eine richtige Tabelle schreiben? Denn wenn ich etwas ändern möchte an der Tabelle und es eine interne Tabelle ist sind die Änderungen ja nicht gespeichert, da sie sich nur im Arbeitsspeicher befindet.

So hoffe das ist etwas verständlich.

MFG

Dzaecko
wreichelt
vor 13 Jahre

Hallo,

du loopst über deine Interne Tabelle, liest in der SAP-Tabelle den entsprechenden Eintrag wenn vorhanden dann ist es ein Modify

wenn der Eintrag neu ist (sy-subrc war ungleich 0) dan ist es ein Insert in die SAP-Tabelle.

Viel Erfolg

Gruß

Wolfgang

Dzaecko
  • Dzaecko
  • SAP Forum - Neuling Thema Starter
vor 13 Jahre
Juhu danke für die schnelle Antwort. Also ich komm der Lösung näher merke ich. Wie gesagt schreibe ich die Excel Daten in eine interne Tabelle. Benutze jetzt den INSERT Befehl um die Daten in meine eigentliche Datenbanktabelle zu schreiben. Und es klappt auch... ein wenig, denn alles ist verschoben und es wird nur die erste Spalte übernommen aber ich finde den Fehler nicht. Ich poste ma den Quellcode und ein paar Screenshots.

MFG

Dzaecko



p.s. Es ist bis jetzt nur der INSERT BEfhel dadrin nochkeine Exception falls der Eintrag schon vorhanden ist.

SPAN {

font-family: "Courier New";

font-size: 10pt;

color: #000000;

background: #FFFFFF;

}

.L1S31 {

font-style: italic;

color: #808080;

}

.L1S32 {

color: #3399FF;

}

.L1S33 {

color: #4DA619;

}

.L1S52 {

color: #0000FF;

}

*&---------------------------------------------------------------------*
*& Report  UPLOAD_EXCEL                                                *
*&---------------------------------------------------------------------*
*& Upload and excel file into an internal table using the following    *
*& function module: ALSM_EXCEL_TO_INTERNAL_TABLE                       *
*&---------------------------------------------------------------------*
REPORT  UPLOAD_EXCEL no standard page heading.

*Data Declaration
*----------------
data: itab like alsmex_tabline occurs 0 with header line.


TYPESBegin of t_record,
    id LIKE itab-value,
    ausleih LIKE itab-value,
    rueck LIKE itab-value,
    benutzer LIKE itab-value,
    End of t_record.
DATA: ZJANNOLL_AUS type standard table of t_record initial size 0,
      wa_record type t_record.
DATA: gd_currentrow type i.

*Selection Screen Declaration
*----------------------------
PARAMETER p_infile like rlgrap-filename.


************************************************************************
*START OF SELECTION
 call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       exporting
            filename                = p_infile
            i_begin_col             = '1'
            i_begin_row             = '2'  "Do not require headings
            i_end_col               = '14'
            i_end_row               = '50'
       tables
            intern                  = itab
       exceptions
            inconsistent_parameters = 1
            upload_ole              = 2
            others                  = 3.
  if sy-subrc <> 0.
    message e010(zz) with text-001"Problem uploading Excel Spreadsheet
  endif.

* Sort table by rows and colums
  sort itab by row col.

* Get first row retrieved
  read table itab index 1.

* Set first row retrieved to current row
  gd_currentrow = itab-row.

  loop at itab.
*   Reset values for next row
    if itab-row ne gd_currentrow.
      append wa_record to ZJANNOLL_AUS.
      clear wa_record.
      gd_currentrow = itab-row.
    endif.

    case itab-col.
      when '0001'.                              "First name
        wa_record-id = itab-value.
      when '0002'.                              "Surname
        wa_record-ausleih = itab-value.
      when '0003'.                              "Age
        wa_record-rueck   = itab-value.
        when '0004'.                              "Age
        wa_record-benutzer   = itab-value.
    endcase.

 INSERT INTO ZJANNOLL_AUS VALUES itab.

  endloop.
  append wa_record to ZJANNOLL_AUS.
*!! Excel data is now contained within the internal table IT_RECORD

* Display report data for illustration purposes
  loop at ZJANNOLL_AUS into wa_record.
    write:/     sy-vline,
           (10) wa_record-id, sy-vline,
           (10) wa_record-ausleih, sy-vline,
           (10) wa_record-rueck, sy-vline,
            (10) wa_record-benutzer, sy-vline.



  endloop.



Hmm irgendwie kann ich gerade keine bilder einfügen...

wreichelt
vor 13 Jahre

Hallo,

also der Report ist ja schon fast richtig aus dem Netz kopiert.

Aber doch mit einigen Fehlern.

Zuerst würde ich anpassen:

  case itab-col.
      when '0001'.                              "First name
        wa_record-id = itab-value.
      when '0002'.                              "Surname
        wa_record-ausleih = itab-value.
      when '0003'.                              "Age
        wa_record-rueck   = itab-value.
        when '0004'.                              "Age
        wa_record-benutzer   = itab-value.

        append wa_record.    "wenn der 4.te Teil gelesen ist, dann ist der Satz vollständig und wird in die interne Struktur wa_record übertragen.

       clear wa_record.        "Satzbereich wird wieder gelöscht
    endcase.

INSERT INTO ZJANNOLL_AUS VALUES itab.

  endloop.

Nach dem Endloop sind alle Excelsätze gelesen und können aus der Struktur wa_record nach .... verarbeitet werden,

sinnvoller weise auch in einem Loop.

Viel Erfolg mit SAP.

Gruß Wolfgang 

 

P.S.: Es gibt nur zwei Meinungen zu SAP, die einen finden es gut und die anderen Spitze

 


  append wa_record to ZJANNOLL_AUS.

 

Dzaecko
  • Dzaecko
  • SAP Forum - Neuling Thema Starter
vor 13 Jahre
So ich hab das jetzt etwas anders gelöst ist auch der reinste kuddelmuddel im code mittler weile. Also ich bekomm jetzt alles schön in meiner Tabelle gespeichert aber... Die Ausgabe der tabelle sieht folgenermaßen aus:

ID       AUS               RÜCK           BEN
1        00.00.0000  00.00.0000  0000
12      20.2..28.0    20.5..19.0     149
21      20.3..13.0    20.6.03.0       23

So also der erste Index (1) enthält nur Nullen und ab Index(2) erscheinen die Daten die zu Index(1) gehören... Außer dem wird das Datum nicht richtig angezeigt.

MFG

Dzaecko
Dzaecko
  • Dzaecko
  • SAP Forum - Neuling Thema Starter
vor 13 Jahre
Wenn ich es mit append record probiere sagt er mit halt das das keine interne Tabelle ist.

Und noch ma mein neuer Code: (und noch ma danke für die hilfe!)

SPAN {

font-family: "Courier New";

font-size: 10pt;

color: #000000;

background: #FFFFFF;

}

.L1S31 {

font-style: italic;

color: #808080;

}

.L1S32 {

color: #3399FF;

}

.L1S33 {

color: #4DA619;

}

.L1S52 {

color: #0000FF;

}

*&---------------------------------------------------------------------*
*& Report  UPLOAD_EXCEL                                                *
*&---------------------------------------------------------------------*
*& Upload and excel file into an internal table using the following    *
*& function module: ALSM_EXCEL_TO_INTERNAL_TABLE                       *
*&---------------------------------------------------------------------*
REPORT  UPLOAD_EXCEL no standard page heading.

*Data Declaration
*----------------
data: itab like alsmex_tabline occurs 0 with header line,
      tab_excel LIKE ZJOAUS1.


TYPESBegin of t_record,
    id LIKE itab-value,
    aus LIKE itab-value,
    rueck LIKE itab-value,
    ben LIKE itab-value,
    End of t_record.
DATA: it_records type standard table of t_record initial size 0,
      wa_record type t_record.
DATA: gd_currentrow type i.

*Selection Screen Declaration
*----------------------------
PARAMETER p_infile like rlgrap-filename.


************************************************************************
*START OF SELECTION
 call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
       exporting
            filename                = p_infile
            i_begin_col             = '1'
            i_begin_row             = '2'  "Do not require headings
            i_end_col               = '4'
            i_end_row               = '100'
       tables
            intern                  = itab
       exceptions
            inconsistent_parameters = 1
            upload_ole              = 2
            others                  = 3.
  if sy-subrc <> 0.
    message e010(zz) with text-001"Problem uploading Excel Spreadsheet
  endif.

* Sort table by rows and colums


* Get first row retrieved
  read table itab index 1.

* Set first row retrieved to current row
  gd_currentrow = itab-row.

  loop at itab.
*   Reset values for next row
    if itab-row ne gd_currentrow.
      append wa_record to it_records.
      clear wa_record.
      gd_currentrow = itab-row.
    endif.

    case itab-col.
      when '0001'.                              "First name
        wa_record-id = itab-value.
        tab_excel-ID =  wa_record-id.

      when '0002'.                              "Surname
        wa_record-aus = itab-value.
        tab_excel-AUS =  wa_record-aus.

      when '0003'.                              "Age
        wa_record-rueck   = itab-value.
        tab_excel-RUECK =  wa_record-rueck.

        when '0004'.                              "Age
        wa_record-ben   = itab-value.
        tab_excel-BEN =  wa_record-ben.



    endcase.


INSERT INTO ZJOAUS1 VALUES tab_excel.

endloop.
  append wa_record to it_records.


*!! Excel data is now contained within the internal table IT_RECORD

* Display report data for illustration purposes
  loop at it_records into wa_record.



    write:/     sy-vline,
           (10) wa_record-id, sy-vline,
           (10) wa_record-aus, sy-vline,
           (10) wa_record-rueck, sy-vline,
            (10) wa_record-ben, sy-vline.
   endloop.