ABAP Select data from SAP table RCONDAD_GCPBASDATA 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 RCONDAD_GCPBASDATA 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 RCONDAD_GCPBASDATA. 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 RCONDAD_GCPBASDATA 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_RCONDAD_GCPBASDATA TYPE STANDARD TABLE OF RCONDAD_GCPBASDATA,
      WA_RCONDAD_GCPBASDATA TYPE RCONDAD_GCPBASDATA,
      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: <RCONDAD_GCPBASDATA> TYPE RCONDAD_GCPBASDATA.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RCONDAD_GCPBASDATA
*  INTO TABLE @DATA(IT_RCONDAD_GCPBASDATA2).
*--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_RCONDAD_GCPBASDATA INDEX 1 INTO DATA(WA_RCONDAD_GCPBASDATA2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RCONDAD_GCPBASDATA ASSIGNING <RCONDAD_GCPBASDATA>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RCONDAD_GCPBASDATA>-MANDT = 1.
<RCONDAD_GCPBASDATA>-BUKRS = 1.
<RCONDAD_GCPBASDATA>-SANLF = 1.
<RCONDAD_GCPBASDATA>-RKEY1 = 1.
<RCONDAD_GCPBASDATA>-RKEY2 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RCONDAD_GCPBASDATA-RKEY3, sy-vline,
WA_RCONDAD_GCPBASDATA-DGUEL_KK, sy-vline,
WA_RCONDAD_GCPBASDATA-NLFD_ANG, sy-vline,
WA_RCONDAD_GCPBASDATA-SKOART, sy-vline,
WA_RCONDAD_GCPBASDATA-DGUEL_KP, sy-vline,
WA_RCONDAD_GCPBASDATA-NSTUFE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RCONDAD_GCPBASDATA 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_RCONDAD_GCPBASDATA 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_RCONDAD_GCPBASDATA INTO WA_RCONDAD_GCPBASDATA. *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 KUNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RCONDAD_GCPBASDATA-KUNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RCONDAD_GCPBASDATA-KUNNR.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit EXCRT, internal->external for field KURS1 CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_RCONDAD_GCPBASDATA-KURS1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RCONDAD_GCPBASDATA-KURS1.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ALPHA, internal->external for field KOSTL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_RCONDAD_GCPBASDATA-KOSTL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_RCONDAD_GCPBASDATA-KOSTL.
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_RCONDAD_GCPBASDATA_STR,
MANDT TYPE STRING,
BUKRS TYPE STRING,
SANLF TYPE STRING,
RKEY1 TYPE STRING,
RKEY2 TYPE STRING,
RKEY3 TYPE STRING,
DGUEL_KK TYPE STRING,
NLFD_ANG TYPE STRING,
SKOART TYPE STRING,
DGUEL_KP TYPE STRING,
NSTUFE TYPE STRING,
XKOARTM TYPE STRING,
SSTATI TYPE STRING,
PKOND TYPE STRING,
BKOND TYPE STRING,
SWHRKOND TYPE STRING,
SBASIS TYPE STRING,
SZSREF TYPE STRING,
SZSREFVZ TYPE STRING,
PFLUCT TYPE STRING,
AMMRHY TYPE STRING,
ATTRHY TYPE STRING,
SZAWS TYPE STRING,
RDIVNR TYPE STRING,
JNULLKON TYPE STRING,
MWSKZ TYPE STRING,
JBMONAT TYPE STRING,
DVALUT TYPE STRING,
DFAELL TYPE STRING,
KUNNR TYPE STRING,
ZLSCH TYPE STRING,
BVTYP TYPE STRING,
MABER TYPE STRING,
SPARTNR TYPE STRING,
RKONT TYPE STRING,
SVULT TYPE STRING,
SFULT TYPE STRING,
SVKALRI TYPE STRING,
SFKALRI TYPE STRING,
AVGSTAGE TYPE STRING,
AFGSTAGE TYPE STRING,
SVKALZUS TYPE STRING,
SFKALZUS TYPE STRING,
SKALID TYPE STRING,
SZBMETH TYPE STRING,
JSOFVERR TYPE STRING,
DALLGEM TYPE STRING,
SZEGEN TYPE STRING,
SBUST TYPE STRING,
SKOPO TYPE STRING,
SALTKOND TYPE STRING,
SZINSANP TYPE STRING,
SINCL TYPE STRING,
SFORMREF TYPE STRING,
SVARNAME TYPE STRING,
SVWERK TYPE STRING,
SVMETH TYPE STRING,
SFWERK TYPE STRING,
SFMETH TYPE STRING,
DPKOND TYPE STRING,
AZGSTAGE TYPE STRING,
SZKALRI TYPE STRING,
DZSREF TYPE STRING,
SKALID2 TYPE STRING,
JGESUCHT TYPE STRING,
KURS1 TYPE STRING,
BBASIS TYPE STRING,
SZWERK TYPE STRING,
SFINCL TYPE STRING,
SRUNDVORF TYPE STRING,
SZWKEY TYPE STRING,
SFVMETH TYPE STRING,
SDWERK TYPE STRING,
SBERECH TYPE STRING,
JPROZR TYPE STRING,
SZEITANT TYPE STRING,
SFANT TYPE STRING,
SFRANZ TYPE STRING,
SKOAREF TYPE STRING,
SBEWSOLL TYPE STRING,
SBEWHABEN TYPE STRING,
SBEWZITI TYPE STRING,
AUSWAHL TYPE STRING,
SBERFIMA TYPE STRING,
JMUSS TYPE STRING,
NFOLGE TYPE STRING,
NHIER TYPE STRING,
KBKOND TYPE STRING,
SBASFIX TYPE STRING,
MANSP TYPE STRING,
ZAHLS TYPE STRING,
SZADRI TYPE STRING,
SZART TYPE STRING,
BKONDQM TYPE STRING,
SFLART TYPE STRING,
JAREA TYPE STRING,
PAY_DATA_C TYPE STRING,
AVGSTAGEVZ TYPE STRING,
AFGSTAGEVZ TYPE STRING,
TXJCD TYPE STRING,
LIFNR TYPE STRING,
JEXPOZINS TYPE STRING,
KOSTL TYPE STRING,
GFZLSCH TYPE STRING,
ZLSPR TYPE STRING,
SROUND TYPE STRING,
SKALIDWT TYPE STRING,
BMWST TYPE STRING,
XCROSS TYPE STRING,
A_PAYDAY TYPE STRING,
RCO TYPE STRING,
BROUNDUNIT TYPE STRING,
PPAYMENT TYPE STRING,
AMMRHYZV TYPE STRING,
RBO TYPE STRING,
STECH_COND TYPE STRING,
SEXCLGUEL TYPE STRING,
SULTGUEL TYPE STRING,
ADGSTAGE TYPE STRING,
SAVGWEIGHT TYPE STRING,
AAVGWEIGHT TYPE STRING,
JAVGCAP TYPE STRING,
PAVGCAP TYPE STRING,
JAVGFLOOR TYPE STRING,
PAVGFLOOR TYPE STRING,
PAVGSPREAD TYPE STRING,
JEXPOINTFACTOR TYPE STRING,
ROUNDDECAVGINTEREST TYPE STRING,
SROUNDAVGINTEREST TYPE STRING,
SFACTORRESET TYPE STRING,END OF T_EKKO_STR. DATA: WA_RCONDAD_GCPBASDATA_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_RCONDAD_GCPBASDATA_STR-MANDT sy-vline
WA_RCONDAD_GCPBASDATA_STR-BUKRS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SANLF sy-vline
WA_RCONDAD_GCPBASDATA_STR-RKEY1 sy-vline
WA_RCONDAD_GCPBASDATA_STR-RKEY2 sy-vline
WA_RCONDAD_GCPBASDATA_STR-RKEY3 sy-vline
WA_RCONDAD_GCPBASDATA_STR-DGUEL_KK sy-vline
WA_RCONDAD_GCPBASDATA_STR-NLFD_ANG sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKOART sy-vline
WA_RCONDAD_GCPBASDATA_STR-DGUEL_KP sy-vline
WA_RCONDAD_GCPBASDATA_STR-NSTUFE sy-vline
WA_RCONDAD_GCPBASDATA_STR-XKOARTM sy-vline
WA_RCONDAD_GCPBASDATA_STR-SSTATI sy-vline
WA_RCONDAD_GCPBASDATA_STR-PKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-BKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SWHRKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBASIS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZSREF sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZSREFVZ sy-vline
WA_RCONDAD_GCPBASDATA_STR-PFLUCT sy-vline
WA_RCONDAD_GCPBASDATA_STR-AMMRHY sy-vline
WA_RCONDAD_GCPBASDATA_STR-ATTRHY sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZAWS sy-vline
WA_RCONDAD_GCPBASDATA_STR-RDIVNR sy-vline
WA_RCONDAD_GCPBASDATA_STR-JNULLKON sy-vline
WA_RCONDAD_GCPBASDATA_STR-MWSKZ sy-vline
WA_RCONDAD_GCPBASDATA_STR-JBMONAT sy-vline
WA_RCONDAD_GCPBASDATA_STR-DVALUT sy-vline
WA_RCONDAD_GCPBASDATA_STR-DFAELL sy-vline
WA_RCONDAD_GCPBASDATA_STR-KUNNR sy-vline
WA_RCONDAD_GCPBASDATA_STR-ZLSCH sy-vline
WA_RCONDAD_GCPBASDATA_STR-BVTYP sy-vline
WA_RCONDAD_GCPBASDATA_STR-MABER sy-vline
WA_RCONDAD_GCPBASDATA_STR-SPARTNR sy-vline
WA_RCONDAD_GCPBASDATA_STR-RKONT sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVULT sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFULT sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVKALRI sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFKALRI sy-vline
WA_RCONDAD_GCPBASDATA_STR-AVGSTAGE sy-vline
WA_RCONDAD_GCPBASDATA_STR-AFGSTAGE sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVKALZUS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFKALZUS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKALID sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZBMETH sy-vline
WA_RCONDAD_GCPBASDATA_STR-JSOFVERR sy-vline
WA_RCONDAD_GCPBASDATA_STR-DALLGEM sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZEGEN sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBUST sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKOPO sy-vline
WA_RCONDAD_GCPBASDATA_STR-SALTKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZINSANP sy-vline
WA_RCONDAD_GCPBASDATA_STR-SINCL sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFORMREF sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVARNAME sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVWERK sy-vline
WA_RCONDAD_GCPBASDATA_STR-SVMETH sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFWERK sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFMETH sy-vline
WA_RCONDAD_GCPBASDATA_STR-DPKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-AZGSTAGE sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZKALRI sy-vline
WA_RCONDAD_GCPBASDATA_STR-DZSREF sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKALID2 sy-vline
WA_RCONDAD_GCPBASDATA_STR-JGESUCHT sy-vline
WA_RCONDAD_GCPBASDATA_STR-KURS1 sy-vline
WA_RCONDAD_GCPBASDATA_STR-BBASIS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZWERK sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFINCL sy-vline
WA_RCONDAD_GCPBASDATA_STR-SRUNDVORF sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZWKEY sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFVMETH sy-vline
WA_RCONDAD_GCPBASDATA_STR-SDWERK sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBERECH sy-vline
WA_RCONDAD_GCPBASDATA_STR-JPROZR sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZEITANT sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFANT sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFRANZ sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKOAREF sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBEWSOLL sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBEWHABEN sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBEWZITI sy-vline
WA_RCONDAD_GCPBASDATA_STR-AUSWAHL sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBERFIMA sy-vline
WA_RCONDAD_GCPBASDATA_STR-JMUSS sy-vline
WA_RCONDAD_GCPBASDATA_STR-NFOLGE sy-vline
WA_RCONDAD_GCPBASDATA_STR-NHIER sy-vline
WA_RCONDAD_GCPBASDATA_STR-KBKOND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SBASFIX sy-vline
WA_RCONDAD_GCPBASDATA_STR-MANSP sy-vline
WA_RCONDAD_GCPBASDATA_STR-ZAHLS sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZADRI sy-vline
WA_RCONDAD_GCPBASDATA_STR-SZART sy-vline
WA_RCONDAD_GCPBASDATA_STR-BKONDQM sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFLART sy-vline
WA_RCONDAD_GCPBASDATA_STR-JAREA sy-vline
WA_RCONDAD_GCPBASDATA_STR-PAY_DATA_C sy-vline
WA_RCONDAD_GCPBASDATA_STR-AVGSTAGEVZ sy-vline
WA_RCONDAD_GCPBASDATA_STR-AFGSTAGEVZ sy-vline
WA_RCONDAD_GCPBASDATA_STR-TXJCD sy-vline
WA_RCONDAD_GCPBASDATA_STR-LIFNR sy-vline
WA_RCONDAD_GCPBASDATA_STR-JEXPOZINS sy-vline
WA_RCONDAD_GCPBASDATA_STR-KOSTL sy-vline
WA_RCONDAD_GCPBASDATA_STR-GFZLSCH sy-vline
WA_RCONDAD_GCPBASDATA_STR-ZLSPR sy-vline
WA_RCONDAD_GCPBASDATA_STR-SROUND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SKALIDWT sy-vline
WA_RCONDAD_GCPBASDATA_STR-BMWST sy-vline
WA_RCONDAD_GCPBASDATA_STR-XCROSS sy-vline
WA_RCONDAD_GCPBASDATA_STR-A_PAYDAY sy-vline
WA_RCONDAD_GCPBASDATA_STR-RCO sy-vline
WA_RCONDAD_GCPBASDATA_STR-BROUNDUNIT sy-vline
WA_RCONDAD_GCPBASDATA_STR-PPAYMENT sy-vline
WA_RCONDAD_GCPBASDATA_STR-AMMRHYZV sy-vline
WA_RCONDAD_GCPBASDATA_STR-RBO sy-vline
WA_RCONDAD_GCPBASDATA_STR-STECH_COND sy-vline
WA_RCONDAD_GCPBASDATA_STR-SEXCLGUEL sy-vline
WA_RCONDAD_GCPBASDATA_STR-SULTGUEL sy-vline
WA_RCONDAD_GCPBASDATA_STR-ADGSTAGE sy-vline
WA_RCONDAD_GCPBASDATA_STR-SAVGWEIGHT sy-vline
WA_RCONDAD_GCPBASDATA_STR-AAVGWEIGHT sy-vline
WA_RCONDAD_GCPBASDATA_STR-JAVGCAP sy-vline
WA_RCONDAD_GCPBASDATA_STR-PAVGCAP sy-vline
WA_RCONDAD_GCPBASDATA_STR-JAVGFLOOR sy-vline
WA_RCONDAD_GCPBASDATA_STR-PAVGFLOOR sy-vline
WA_RCONDAD_GCPBASDATA_STR-PAVGSPREAD sy-vline
WA_RCONDAD_GCPBASDATA_STR-JEXPOINTFACTOR sy-vline
WA_RCONDAD_GCPBASDATA_STR-ROUNDDECAVGINTEREST sy-vline
WA_RCONDAD_GCPBASDATA_STR-SROUNDAVGINTEREST sy-vline
WA_RCONDAD_GCPBASDATA_STR-SFACTORRESET sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.