Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Program to upload data from dat file to Z-table

Former Member
0 Kudos

Dear ABAP Gurus and Experts,

I am trying to create a program to upload my Attendance machine (Biometric) data into ztable (say - ZDLYATND).

in this table ATND_ID is primary key and it will be an auto generated No. For this I have created an object ZDLYATND in SNRO and return a program for this as follows.

*************************************************************

program ZATND_ID message-id s#.

 

data:

number type i.

call function 'NUMBER_GET_NEXT'

exporting

   nr_range_nr = '01'

   object = 'ZDLYATND'

importing

  number = number

exceptions

  interval_not_found = 1

  number_range_not_intern = 2

  object_not_found = 3

  quantity_is_0 = 4

  quantity_is_not_1 = 5

  interval_overflow = 6

  buffer_overflow = 7

  others = 8

.

if sy-subrc <> 0.

  message id sy-msgid type sy-msgty number sy-msgno

     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

***********************************************************************

I have written another program to upload the data from .dat file to z-table.

******************************************************************************

*&---------------------------------------------------------------------*

*& Report  ZDLYATND                                                    *

*&                                                                     *

*&---------------------------------------------------------------------*

*&                                                                     *

*&                                                                     *

*&---------------------------------------------------------------------*

program zdlyatnd message-id s#.

tables: zdlyatnd.

data : begin of itab occurs 0,

atnd_id like zdlyatnd-atnd_id,

atnd_emp like zdlyatnd-atnd_emp,

atnd_dat like zdlyatnd-atnd_dat,

atnd_tim like zdlyatnd-atnd_tim,

atnd_flg1 like zdlyatnd-atnd_flg1,

atnd_flg2 like zdlyatnd-atnd_flg2,

atnd_flg3 like zdlyatnd-atnd_flg3,

atnd_flg4 like zdlyatnd-atnd_flg4,

end of itab.

parameters: p_file type localfile default 'C:\Documents and Settings\Admin\Desktop' obligatory.

parameters:date like zdlyatnd-atnd_dat.

at selection-screen on value-request for p_file.

call function 'F4_FILENAME'

exporting

field_name = 'P_FILE'

importing

file_name = p_file.

call function 'WS_UPLOAD'

*CALL FUNCTION 'NUMBER_GET_NEXT'.

*ATND_ID = NUMBER.

    exporting

         filename            = '1_attlog'

     tables

          data_tab            = itab

     exceptions

          conversion_error    = 1

          file_open_error     = 2

          file_read_error     = 3

          invalid_table_width = 4

loop at itab.

    clear zdlyatnd.

    move-corresponding itab to zdlyatnd.

    insert zdlyatnd.

    commit work.

***********************************************************

Now, I am looking a way to call this first program in to second program. So, it will insert the value of primary key in table automatically. I also request please check my program.

With thanks & regards,

Devendra Singh

1 ACCEPTED SOLUTION

Former Member
0 Kudos

You do not need to call the first program. You can achieve the same by calling the FM 'NUMBER_GET_NEXT' with same parameters directly within the Loop. and assign that generated number to work area ZDLYATND before the INSERT statement.

7 REPLIES 7

Former Member
0 Kudos

You do not need to call the first program. You can achieve the same by calling the FM 'NUMBER_GET_NEXT' with same parameters directly within the Loop. and assign that generated number to work area ZDLYATND before the INSERT statement.

0 Kudos

Dear Ritwik,

I have modified the program as you told. But it is inserting only value for ZATND_ID only one row. System is not updating value for another fields. please see the attachment. Here I am attaching my codes. can you check it - where am I wrong?

******************************************************************************************

*&---------------------------------------------------------------------*

*& Report  ZDLYATND                                                    *

*&                                                                     *

*&---------------------------------------------------------------------*

*&                                                                     *

*&                                                                     *

*&---------------------------------------------------------------------*

program ZDLYATND message-id s#.

tables: ZDLYATND.

Data : begin of itab occurs 0,

ATND_ID like ZDLYATND-ATND_ID,

ATND_EMP like ZDLYATND-ATND_EMP,

ATND_DAT like ZDLYATND-ATND_DAT,

ATND_TIM like ZDLYATND-ATND_TIM,

ATND_FLG1 like ZDLYATND-ATND_FLG1,

ATND_FLG2 like ZDLYATND-ATND_FLG2,

ATND_FLG3 like ZDLYATND-ATND_FLG3,

ATND_FLG4 like ZDLYATND-ATND_FLG4,

end of itab.

PARAMETERS: p_file TYPE localfile DEFAULT 'C:\Documents and Settings\Admin\Desktop' OBLIGATORY.

parameters:date like ZDLYATND-ATND_DAT.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

call function 'WS_UPLOAD'

*CALL FUNCTION 'NUMBER_GET_NEXT'.

*ATND_ID = NUMBER.

    exporting

         filename            = '1_attlog'

     tables

          data_tab            = itab

     exceptions

          conversion_error    = 1

          file_open_error     = 2

          file_read_error     = 3

          invalid_table_width = 4

loop at itab.

        DATA:

        NUMBER TYPE I.

        CALL FUNCTION 'NUMBER_GET_NEXT'

        EXPORTING

           nr_range_nr = '01'

           object = 'ZDLYATND'

        IMPORTING

          NUMBER = NUMBER

        EXCEPTIONS

          INTERVAL_NOT_FOUND = 1

          NUMBER_RANGE_NOT_INTERN = 2

          OBJECT_NOT_FOUND = 3

          QUANTITY_IS_0 = 4

          QUANTITY_IS_NOT_1 = 5

          INTERVAL_OVERFLOW = 6

          BUFFER_OVERFLOW = 7

          OTHERS = 8

        .

        IF sy-subrc <> 0.

          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

        ENDIF.

itab-ATND_ID = NUMBER.

    clear ZDLYATND.

    move-corresponding itab to ZDLYATND.

    insert ZDLYATND.

    commit work.

With thanks and regards,

Devendra Singh Chauhan

0 Kudos

Hi,

        put below code after  " itab-ATND_ID = NUMBER. " and make one work_area for itab --->  wa_itab.

      

itab-ATND_ID = NUMBER.

            

          MODIFY itab INDEX sy-tabix FROM wa_itab

         TRANSPORTING ATND_ID..

clear ZDLYATND. 

    move-corresponding itab to ZDLYATND.

    insert ZDLYATND.

    commit work.

Regard's

Smruuti

0 Kudos

do not use insert command inside your loop ,it will affect your performance too much..
first fill the internal table with all the values inside the loop... you can then check too in debugging whether you are getting values you want in your internal table...
and after the loop.

INSERT <dbtab> FROM TABLE <itab>.

commit work.

0 Kudos

Dear Maverick mvx,

First fill the internal table with all the values inside the loop...

Please, Can you tell me how can we do it.

With thanks and regards,

Devendra Singh

0 Kudos

define gt_zdlyatnd type standard table of zdlyatnd... and a workarea wa_zdlyatnd....
now inside the loop , move corresponding itab to wa_zdlyatnd.
append wa_zdlyatnd to gt_zdlyatnd...
clear wa_zdlyatnd....
then after loop you can use  insert command and commit work....
also its always good to use internal table without header... so if you can then try converting itab to without header line....

raymond_giuseppi
Active Contributor
0 Kudos

As already suggested call FM NUMBER_GET_NEXT, but I would suggest to use QUANTITY parameter to get multiple numbers in one call (for performance) if many records are loaded at once (you will get in return the last and the number of consecutive numbers allocated)

Another solution would be to insert those events with some mapping in HR standard interface (table cc1tev) via BAPI_CC1_UPLOAD_TIMEEVENT and then trigger post to HR (nfotype 2011) via HR_CC1_TIMEEVENT_POST (or transaction PT41)

Also did you ask  your device manufacturer for support of the standard idoc connectors for this ?

Regards,

Raymond