ABAP Select data from SAP table TISU_CSMLDOCD_BR 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 TISU_CSMLDOCD_BR 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 TISU_CSMLDOCD_BR. 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 TISU_CSMLDOCD_BR 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_TISU_CSMLDOCD_BR TYPE STANDARD TABLE OF TISU_CSMLDOCD_BR,
      WA_TISU_CSMLDOCD_BR TYPE TISU_CSMLDOCD_BR,
      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: <TISU_CSMLDOCD_BR> TYPE TISU_CSMLDOCD_BR.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_TISU_CSMLDOCD_BR.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM TISU_CSMLDOCD_BR
  INTO TABLE IT_TISU_CSMLDOCD_BR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TISU_CSMLDOCD_BR
*  INTO TABLE @DATA(IT_TISU_CSMLDOCD_BR2).
*--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_TISU_CSMLDOCD_BR INDEX 1 INTO DATA(WA_TISU_CSMLDOCD_BR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TISU_CSMLDOCD_BR ASSIGNING <TISU_CSMLDOCD_BR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TISU_CSMLDOCD_BR>-MANDT = 1.
<TISU_CSMLDOCD_BR>-DRAFTUUID = 1.
<TISU_CSMLDOCD_BR>-SCENARIOID = 1.
<TISU_CSMLDOCD_BR>-ORIGINALPRINTDOCUMENT = 1.
<TISU_CSMLDOCD_BR>-SIMULATEDPRINTDOCUMENT = 1.
ENDLOOP.

LOOP AT IT_TISU_CSMLDOCD_BR INTO WA_TISU_CSMLDOCD_BR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TISU_CSMLDOCD_BR-DOCUMENTCREATIONDATE, sy-vline,
WA_TISU_CSMLDOCD_BR-INSTALLATION, sy-vline,
WA_TISU_CSMLDOCD_BR-CONTRACT, sy-vline,
WA_TISU_CSMLDOCD_BR-BUSINESSPARTNER, sy-vline,
WA_TISU_CSMLDOCD_BR-BEGINBILLPERIOD, sy-vline,
WA_TISU_CSMLDOCD_BR-ENDBILLPERIOD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TISU_CSMLDOCD_BR 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_TISU_CSMLDOCD_BR 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_TISU_CSMLDOCD_BR INTO WA_TISU_CSMLDOCD_BR. *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 ALPHA, internal->external for field SCENARIOID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-SCENARIOID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-SCENARIOID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ORIGINALPRINTDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-ORIGINALPRINTDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-ORIGINALPRINTDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SIMULATEDPRINTDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-SIMULATEDPRINTDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-SIMULATEDPRINTDOCUMENT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field INSTALLATION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-INSTALLATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-INSTALLATION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CONTRACT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-CONTRACT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-CONTRACT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BUSINESSPARTNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-BUSINESSPARTNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-BUSINESSPARTNER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field BILLINGDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TISU_CSMLDOCD_BR-BILLINGDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TISU_CSMLDOCD_BR-BILLINGDOCUMENT.
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_TISU_CSMLDOCD_BR_STR,
MANDT TYPE STRING,
DRAFTUUID TYPE STRING,
SCENARIOID TYPE STRING,
ORIGINALPRINTDOCUMENT TYPE STRING,
SIMULATEDPRINTDOCUMENT TYPE STRING,
DOCUMENTCREATIONDATE TYPE STRING,
INSTALLATION TYPE STRING,
CONTRACT TYPE STRING,
BUSINESSPARTNER TYPE STRING,
BEGINBILLPERIOD TYPE STRING,
ENDBILLPERIOD TYPE STRING,
BILLINGDOCUMENT TYPE STRING,
DOCUMENTITEMTYPE TYPE STRING,
OPERATIONKEY TYPE STRING,
PRIORORDERING TYPE STRING,
MAINOPERATIONDOCUMENTITEM TYPE STRING,
SUBOPERATIONDOCUMENTITEM TYPE STRING,
FICAPOSTINGSTATUS TYPE STRING,
HASACTIVEENTITY TYPE STRING,
DRAFTENTITYCREATIONDATETIME TYPE STRING,
DRAFTENTITYLASTCHANGEDATETIME TYPE STRING,
DRAFTADMINISTRATIVEDATAUUID TYPE STRING,
DRAFTENTITYCONSISTENCYSTATUS TYPE STRING,
DRAFTENTITYOPERATIONCODE TYPE STRING,END OF T_EKKO_STR. DATA: WA_TISU_CSMLDOCD_BR_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_TISU_CSMLDOCD_BR_STR-MANDT sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTUUID sy-vline
WA_TISU_CSMLDOCD_BR_STR-SCENARIOID sy-vline
WA_TISU_CSMLDOCD_BR_STR-ORIGINALPRINTDOCUMENT sy-vline
WA_TISU_CSMLDOCD_BR_STR-SIMULATEDPRINTDOCUMENT sy-vline
WA_TISU_CSMLDOCD_BR_STR-DOCUMENTCREATIONDATE sy-vline
WA_TISU_CSMLDOCD_BR_STR-INSTALLATION sy-vline
WA_TISU_CSMLDOCD_BR_STR-CONTRACT sy-vline
WA_TISU_CSMLDOCD_BR_STR-BUSINESSPARTNER sy-vline
WA_TISU_CSMLDOCD_BR_STR-BEGINBILLPERIOD sy-vline
WA_TISU_CSMLDOCD_BR_STR-ENDBILLPERIOD sy-vline
WA_TISU_CSMLDOCD_BR_STR-BILLINGDOCUMENT sy-vline
WA_TISU_CSMLDOCD_BR_STR-DOCUMENTITEMTYPE sy-vline
WA_TISU_CSMLDOCD_BR_STR-OPERATIONKEY sy-vline
WA_TISU_CSMLDOCD_BR_STR-PRIORORDERING sy-vline
WA_TISU_CSMLDOCD_BR_STR-MAINOPERATIONDOCUMENTITEM sy-vline
WA_TISU_CSMLDOCD_BR_STR-SUBOPERATIONDOCUMENTITEM sy-vline
WA_TISU_CSMLDOCD_BR_STR-FICAPOSTINGSTATUS sy-vline
WA_TISU_CSMLDOCD_BR_STR-HASACTIVEENTITY sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTENTITYCREATIONDATETIME sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTENTITYLASTCHANGEDATETIME sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTADMINISTRATIVEDATAUUID sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTENTITYCONSISTENCYSTATUS sy-vline
WA_TISU_CSMLDOCD_BR_STR-DRAFTENTITYOPERATIONCODE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.