ABAP Select data from SAP table SOOD into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP SOOD table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to SOOD. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the SOOD table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_SOOD TYPE STANDARD TABLE OF SOOD, WA_SOOD TYPE SOOD, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <SOOD> TYPE SOOD. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_SOOD. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM SOOD INTO TABLE IT_SOOD. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM SOOD * INTO TABLE @DATA(IT_SOOD2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_SOOD INDEX 1 INTO DATA(WA_SOOD2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_SOOD ASSIGNING <SOOD>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<SOOD>-MANDT = 1.
<SOOD>-OBJTP = 1.
<SOOD>-OBJYR = 1.
<SOOD>-OBJNO = 1.
<SOOD>-OBJLA = 1.
ENDLOOP. LOOP AT IT_SOOD INTO WA_SOOD. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_SOOD-OBJSRT, sy-vline,
WA_SOOD-OBJNAM, sy-vline,
WA_SOOD-OBJDES, sy-vline,
WA_SOOD-OWNTP, sy-vline,
WA_SOOD-OWNYR, sy-vline,
WA_SOOD-OWNNO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_SOOD you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_SOOD TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_SOOD INTO WA_SOOD. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ISOLA, internal->external for field OBJLA CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_SOOD-OBJLA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_SOOD-OBJLA.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_SOOD_STR,
MANDT TYPE STRING,
OBJTP TYPE STRING,
OBJYR TYPE STRING,
OBJNO TYPE STRING,
OBJLA TYPE STRING,
OBJSRT TYPE STRING,
OBJNAM TYPE STRING,
OBJDES TYPE STRING,
OWNTP TYPE STRING,
OWNYR TYPE STRING,
OWNNO TYPE STRING,
OWNNAM TYPE STRING,
CROTP TYPE STRING,
CROYR TYPE STRING,
CRONO TYPE STRING,
CRONAM TYPE STRING,
CRDAT TYPE STRING,
CRTIM TYPE STRING,
CHOTP TYPE STRING,
CHOYR TYPE STRING,
CHONO TYPE STRING,
CHONAM TYPE STRING,
CHDAT TYPE STRING,
CHTIM TYPE STRING,
NOTTP TYPE STRING,
NOTYR TYPE STRING,
NOTNO TYPE STRING,
OBJAPP TYPE STRING,
OBJFIL TYPE STRING,
FOLRG TYPE STRING,
NOTES TYPE STRING,
UHCNT TYPE STRING,
ENCCNT TYPE STRING,
PTFOL TYPE STRING,
PTENC TYPE STRING,
PTHYP TYPE STRING,
PTNOT TYPE STRING,
PTMBO TYPE STRING,
PAFOL TYPE STRING,
PAENC TYPE STRING,
PAHYP TYPE STRING,
PANOT TYPE STRING,
PAMBO TYPE STRING,
ARCHI TYPE STRING,
LADAT TYPE STRING,
DLDAT TYPE STRING,
DLTIM TYPE STRING,
OBJPRI TYPE STRING,
OBJSNS TYPE STRING,
OBJENC TYPE STRING,
OBJSND TYPE STRING,
SDDAT TYPE STRING,
SDTIM TYPE STRING,
RECCNT TYPE STRING,
RRDCNT TYPE STRING,
RRRCNT TYPE STRING,
RRPCNT TYPE STRING,
RARCNT TYPE STRING,
RAPCNT TYPE STRING,
RATCNT TYPE STRING,
REXCNT TYPE STRING,
RCPCNT TYPE STRING,
RBCCNT TYPE STRING,
ACONE TYPE STRING,
ACOUT TYPE STRING,
FROUT TYPE STRING,
VMTYP TYPE STRING,
SKIPS TYPE STRING,
ACNAM TYPE STRING,
ACMEM TYPE STRING,
HYPTP TYPE STRING,
HYPYR TYPE STRING,
HYPNO TYPE STRING,
AUTTP TYPE STRING,
AUTYR TYPE STRING,
AUTNO TYPE STRING,
PCTRL TYPE STRING,
CCOTP TYPE STRING,
CCOYR TYPE STRING,
CCONO TYPE STRING,
OBJCP TYPE STRING,
PRTCT TYPE STRING,
FIXED TYPE STRING,
EXTHD TYPE STRING,
EXTCT TYPE STRING,
FILE_EXT TYPE STRING,
OBJLEN TYPE STRING,
OBJDBLEN TYPE STRING,
CREATOR TYPE STRING,
ATTLEN TYPE STRING,
IF_DOC_BCS TYPE STRING,
IF_DOC_CLS TYPE STRING,END OF T_EKKO_STR. DATA: WA_SOOD_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_SOOD_STR-MANDT sy-vline
WA_SOOD_STR-OBJTP sy-vline
WA_SOOD_STR-OBJYR sy-vline
WA_SOOD_STR-OBJNO sy-vline
WA_SOOD_STR-OBJLA sy-vline
WA_SOOD_STR-OBJSRT sy-vline
WA_SOOD_STR-OBJNAM sy-vline
WA_SOOD_STR-OBJDES sy-vline
WA_SOOD_STR-OWNTP sy-vline
WA_SOOD_STR-OWNYR sy-vline
WA_SOOD_STR-OWNNO sy-vline
WA_SOOD_STR-OWNNAM sy-vline
WA_SOOD_STR-CROTP sy-vline
WA_SOOD_STR-CROYR sy-vline
WA_SOOD_STR-CRONO sy-vline
WA_SOOD_STR-CRONAM sy-vline
WA_SOOD_STR-CRDAT sy-vline
WA_SOOD_STR-CRTIM sy-vline
WA_SOOD_STR-CHOTP sy-vline
WA_SOOD_STR-CHOYR sy-vline
WA_SOOD_STR-CHONO sy-vline
WA_SOOD_STR-CHONAM sy-vline
WA_SOOD_STR-CHDAT sy-vline
WA_SOOD_STR-CHTIM sy-vline
WA_SOOD_STR-NOTTP sy-vline
WA_SOOD_STR-NOTYR sy-vline
WA_SOOD_STR-NOTNO sy-vline
WA_SOOD_STR-OBJAPP sy-vline
WA_SOOD_STR-OBJFIL sy-vline
WA_SOOD_STR-FOLRG sy-vline
WA_SOOD_STR-NOTES sy-vline
WA_SOOD_STR-UHCNT sy-vline
WA_SOOD_STR-ENCCNT sy-vline
WA_SOOD_STR-PTFOL sy-vline
WA_SOOD_STR-PTENC sy-vline
WA_SOOD_STR-PTHYP sy-vline
WA_SOOD_STR-PTNOT sy-vline
WA_SOOD_STR-PTMBO sy-vline
WA_SOOD_STR-PAFOL sy-vline
WA_SOOD_STR-PAENC sy-vline
WA_SOOD_STR-PAHYP sy-vline
WA_SOOD_STR-PANOT sy-vline
WA_SOOD_STR-PAMBO sy-vline
WA_SOOD_STR-ARCHI sy-vline
WA_SOOD_STR-LADAT sy-vline
WA_SOOD_STR-DLDAT sy-vline
WA_SOOD_STR-DLTIM sy-vline
WA_SOOD_STR-OBJPRI sy-vline
WA_SOOD_STR-OBJSNS sy-vline
WA_SOOD_STR-OBJENC sy-vline
WA_SOOD_STR-OBJSND sy-vline
WA_SOOD_STR-SDDAT sy-vline
WA_SOOD_STR-SDTIM sy-vline
WA_SOOD_STR-RECCNT sy-vline
WA_SOOD_STR-RRDCNT sy-vline
WA_SOOD_STR-RRRCNT sy-vline
WA_SOOD_STR-RRPCNT sy-vline
WA_SOOD_STR-RARCNT sy-vline
WA_SOOD_STR-RAPCNT sy-vline
WA_SOOD_STR-RATCNT sy-vline
WA_SOOD_STR-REXCNT sy-vline
WA_SOOD_STR-RCPCNT sy-vline
WA_SOOD_STR-RBCCNT sy-vline
WA_SOOD_STR-ACONE sy-vline
WA_SOOD_STR-ACOUT sy-vline
WA_SOOD_STR-FROUT sy-vline
WA_SOOD_STR-VMTYP sy-vline
WA_SOOD_STR-SKIPS sy-vline
WA_SOOD_STR-ACNAM sy-vline
WA_SOOD_STR-ACMEM sy-vline
WA_SOOD_STR-HYPTP sy-vline
WA_SOOD_STR-HYPYR sy-vline
WA_SOOD_STR-HYPNO sy-vline
WA_SOOD_STR-AUTTP sy-vline
WA_SOOD_STR-AUTYR sy-vline
WA_SOOD_STR-AUTNO sy-vline
WA_SOOD_STR-PCTRL sy-vline
WA_SOOD_STR-CCOTP sy-vline
WA_SOOD_STR-CCOYR sy-vline
WA_SOOD_STR-CCONO sy-vline
WA_SOOD_STR-OBJCP sy-vline
WA_SOOD_STR-PRTCT sy-vline
WA_SOOD_STR-FIXED sy-vline
WA_SOOD_STR-EXTHD sy-vline
WA_SOOD_STR-EXTCT sy-vline
WA_SOOD_STR-FILE_EXT sy-vline
WA_SOOD_STR-OBJLEN sy-vline
WA_SOOD_STR-OBJDBLEN sy-vline
WA_SOOD_STR-CREATOR sy-vline
WA_SOOD_STR-ATTLEN sy-vline
WA_SOOD_STR-IF_DOC_BCS sy-vline
WA_SOOD_STR-IF_DOC_CLS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.