ABAP Select data from SAP table FINS_RR_DATA2B 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 FINS_RR_DATA2B 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 FINS_RR_DATA2B. 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 FINS_RR_DATA2B 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_FINS_RR_DATA2B TYPE STANDARD TABLE OF FINS_RR_DATA2B,
      WA_FINS_RR_DATA2B TYPE FINS_RR_DATA2B,
      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: <FINS_RR_DATA2B> TYPE FINS_RR_DATA2B.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM FINS_RR_DATA2B
*  INTO TABLE @DATA(IT_FINS_RR_DATA2B2).
*--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_FINS_RR_DATA2B INDEX 1 INTO DATA(WA_FINS_RR_DATA2B2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_FINS_RR_DATA2B ASSIGNING <FINS_RR_DATA2B>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<FINS_RR_DATA2B>-MANDT = 1.
<FINS_RR_DATA2B>-RLDNR = 1.
<FINS_RR_DATA2B>-OBJNR = 1.
<FINS_RR_DATA2B>-PS_POSID = 1.
<FINS_RR_DATA2B>-PS_PSP_PNR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_FINS_RR_DATA2B-PS_PSPID, sy-vline,
WA_FINS_RR_DATA2B-PAOBJNR, sy-vline,
WA_FINS_RR_DATA2B-AUFNR, sy-vline,
WA_FINS_RR_DATA2B-KDAUF, sy-vline,
WA_FINS_RR_DATA2B-KDPOS, sy-vline,
WA_FINS_RR_DATA2B-SERVICE_DOC_ID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_FINS_RR_DATA2B 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_FINS_RR_DATA2B 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_FINS_RR_DATA2B INTO WA_FINS_RR_DATA2B. *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 RLDNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-RLDNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-RLDNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ABPSN, internal->external for field PS_POSID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-PS_POSID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-PS_POSID.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ABPSP, internal->external for field PS_PSP_PNR CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-PS_PSP_PNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-PS_PSP_PNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ABPSN, internal->external for field PS_PSPID CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-PS_PSPID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-PS_PSPID.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-MATNR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit CUNIT, internal->external for field RUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_FINS_RR_DATA2B-RUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_FINS_RR_DATA2B-RUNIT.
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_FINS_RR_DATA2B_STR,
MANDT TYPE STRING,
RLDNR TYPE STRING,
OBJNR TYPE STRING,
PS_POSID TYPE STRING,
PS_PSP_PNR TYPE STRING,
PS_PSPID TYPE STRING,
PAOBJNR TYPE STRING,
AUFNR TYPE STRING,
KDAUF TYPE STRING,
KDPOS TYPE STRING,
SERVICE_DOC_ID TYPE STRING,
SERVICE_DOC_ITEM_ID TYPE STRING,
SERVICE_CONTRACT_ID TYPE STRING,
SERVICE_CONTRACT_ITEM_ID TYPE STRING,
VTKEY TYPE STRING,
VTPOS TYPE STRING,
HKONT TYPE STRING,
GKONT TYPE STRING,
SLALITTYPE TYPE STRING,
RTIND TYPE STRING,
BUKRS TYPE STRING,
WERKS TYPE STRING,
GSBER TYPE STRING,
PRCTR TYPE STRING,
MATNR TYPE STRING,
PERNR TYPE STRING,
RSRCE TYPE STRING,
UPRCTR TYPE STRING,
ACCASTY TYPE STRING,
RWCUR TYPE STRING,
RHCUR TYPE STRING,
RKCUR TYPE STRING,
ROCUR TYPE STRING,
RVCUR TYPE STRING,
RBCUR TYPE STRING,
RCCUR TYPE STRING,
RDCUR TYPE STRING,
RECUR TYPE STRING,
RFCUR TYPE STRING,
RGCUR TYPE STRING,
RCO_OCUR TYPE STRING,
RUNIT TYPE STRING,
MAX_BUDAT TYPE STRING,
WSL TYPE STRING,
HSL TYPE STRING,
KSL TYPE STRING,
KFSL TYPE STRING,
OSL TYPE STRING,
VSL TYPE STRING,
BSL TYPE STRING,
CSL TYPE STRING,
DSL TYPE STRING,
ESL TYPE STRING,
FSL TYPE STRING,
GSL TYPE STRING,
CO_OSL TYPE STRING,
MSL TYPE STRING,END OF T_EKKO_STR. DATA: WA_FINS_RR_DATA2B_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_FINS_RR_DATA2B_STR-MANDT sy-vline
WA_FINS_RR_DATA2B_STR-RLDNR sy-vline
WA_FINS_RR_DATA2B_STR-OBJNR sy-vline
WA_FINS_RR_DATA2B_STR-PS_POSID sy-vline
WA_FINS_RR_DATA2B_STR-PS_PSP_PNR sy-vline
WA_FINS_RR_DATA2B_STR-PS_PSPID sy-vline
WA_FINS_RR_DATA2B_STR-PAOBJNR sy-vline
WA_FINS_RR_DATA2B_STR-AUFNR sy-vline
WA_FINS_RR_DATA2B_STR-KDAUF sy-vline
WA_FINS_RR_DATA2B_STR-KDPOS sy-vline
WA_FINS_RR_DATA2B_STR-SERVICE_DOC_ID sy-vline
WA_FINS_RR_DATA2B_STR-SERVICE_DOC_ITEM_ID sy-vline
WA_FINS_RR_DATA2B_STR-SERVICE_CONTRACT_ID sy-vline
WA_FINS_RR_DATA2B_STR-SERVICE_CONTRACT_ITEM_ID sy-vline
WA_FINS_RR_DATA2B_STR-VTKEY sy-vline
WA_FINS_RR_DATA2B_STR-VTPOS sy-vline
WA_FINS_RR_DATA2B_STR-HKONT sy-vline
WA_FINS_RR_DATA2B_STR-GKONT sy-vline
WA_FINS_RR_DATA2B_STR-SLALITTYPE sy-vline
WA_FINS_RR_DATA2B_STR-RTIND sy-vline
WA_FINS_RR_DATA2B_STR-BUKRS sy-vline
WA_FINS_RR_DATA2B_STR-WERKS sy-vline
WA_FINS_RR_DATA2B_STR-GSBER sy-vline
WA_FINS_RR_DATA2B_STR-PRCTR sy-vline
WA_FINS_RR_DATA2B_STR-MATNR sy-vline
WA_FINS_RR_DATA2B_STR-PERNR sy-vline
WA_FINS_RR_DATA2B_STR-RSRCE sy-vline
WA_FINS_RR_DATA2B_STR-UPRCTR sy-vline
WA_FINS_RR_DATA2B_STR-ACCASTY sy-vline
WA_FINS_RR_DATA2B_STR-RWCUR sy-vline
WA_FINS_RR_DATA2B_STR-RHCUR sy-vline
WA_FINS_RR_DATA2B_STR-RKCUR sy-vline
WA_FINS_RR_DATA2B_STR-ROCUR sy-vline
WA_FINS_RR_DATA2B_STR-RVCUR sy-vline
WA_FINS_RR_DATA2B_STR-RBCUR sy-vline
WA_FINS_RR_DATA2B_STR-RCCUR sy-vline
WA_FINS_RR_DATA2B_STR-RDCUR sy-vline
WA_FINS_RR_DATA2B_STR-RECUR sy-vline
WA_FINS_RR_DATA2B_STR-RFCUR sy-vline
WA_FINS_RR_DATA2B_STR-RGCUR sy-vline
WA_FINS_RR_DATA2B_STR-RCO_OCUR sy-vline
WA_FINS_RR_DATA2B_STR-RUNIT sy-vline
WA_FINS_RR_DATA2B_STR-MAX_BUDAT sy-vline
WA_FINS_RR_DATA2B_STR-WSL sy-vline
WA_FINS_RR_DATA2B_STR-HSL sy-vline
WA_FINS_RR_DATA2B_STR-KSL sy-vline
WA_FINS_RR_DATA2B_STR-KFSL sy-vline
WA_FINS_RR_DATA2B_STR-OSL sy-vline
WA_FINS_RR_DATA2B_STR-VSL sy-vline
WA_FINS_RR_DATA2B_STR-BSL sy-vline
WA_FINS_RR_DATA2B_STR-CSL sy-vline
WA_FINS_RR_DATA2B_STR-DSL sy-vline
WA_FINS_RR_DATA2B_STR-ESL sy-vline
WA_FINS_RR_DATA2B_STR-FSL sy-vline
WA_FINS_RR_DATA2B_STR-GSL sy-vline
WA_FINS_RR_DATA2B_STR-CO_OSL sy-vline
WA_FINS_RR_DATA2B_STR-MSL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.